﻿using System;
using AMM.Business;
using AMM.Model;
using AMM.Model.Finance;

namespace AMM.UserControls {
    public partial class BankAccountSearchControl : BaseSearchControl {

        public override BaseSearchModel GetSearchModel() {
            int enabledValue = Convert.ToInt32(this.cmbIsEnabled.SelectedValue);
            int currencyValue = Convert.ToInt32(this.cmbCurrency.SelectedValue);
            int finacialAccountTypeValue = Convert.ToInt32(this.cmbFinacialAccountType.SelectedValue);

            BankAccountSearchModel searchResult = new BankAccountSearchModel();
            searchResult.Code = this.tbCode.Text;
            searchResult.BankName = this.tbBankName.Text;
            searchResult.BankAccountName = this.tbBankAccountName.Text;
            searchResult.CurrencyId = currencyValue;
            searchResult.FinancialAccountTypeId = finacialAccountTypeValue;
            searchResult.IsEnabled = Convert.ToBoolean(enabledValue);

            if (enabledValue == -1) { searchResult.IsEnabled = null; }
            if (currencyValue == 0) { searchResult.CurrencyId = null; }
            if (finacialAccountTypeValue == 0) { searchResult.FinancialAccountTypeId = null; }

            return searchResult;
        }

        public override void ResetSearchModel() {
            this.tbCode.Clear();
            this.tbBankName.Clear();
            this.tbBankAccountName.Clear();
            this.cmbIsEnabled.SelectedValue = "-1";
            this.cmbCurrency.SelectedIndex = 0;
            this.cmbFinacialAccountType.SelectedValue = 0;
        }

        public BankAccountSearchControl() {
            this.InitializeComponent();

            this.BindIsEnabled(this.cmbIsEnabled);
            this.BindBasics(this.cmbCurrency, BasicsType.Currency);
            this.BindBasics(this.cmbFinacialAccountType, BasicsType.FinancialAccountType);
        }
    }
}
